package com.gimi.cloud.jimi.common.utils;

import com.github.pagehelper.PageInfo;

import java.util.List;

/**
 * 分页Model
 * 
 * @author xx
 * @version 2.0
 * @since 2014年1月28日
 */
public class Page<T> {


	/** 总数 */
	private long total;
	/** 每页条数 */
	private int pageSize;
	/** 总页数 */
	private int pages;
	/** 当前页 */
	private int currentPage;
	/** 数据列表 */
	private List<T> list;
	/** 每页条数-默认10条 */
	public static int ROWS = 10;

	public Page() {
		super();
	}

	public Page(int total, int currentPage) {
		this(total, currentPage, ROWS);
	}

	public Page(int total, int currentPage, int pageSize) {
		super();
		this.total = total;
		this.currentPage = currentPage == 0 ? 1 : currentPage;
		this.pageSize = pageSize;
		this.pages = (int) Math.ceil((total + 0.0) / pageSize);
	}

	public Page(PageInfo<T> pageInfo) {
		super();
		this.total = pageInfo.getTotal();
		this.currentPage = pageInfo.getPageNum();
		this.pageSize = pageInfo.getPageSize();
		this.pages = (int) Math.ceil((total + 0.0) / pageSize);
		this.list=pageInfo.getList();
	}



	/**
	 * 当前页是否有上一页
	 * 
	 * @return
	 */
	public boolean hasPreview() {
		if (pages > 1 && currentPage > 1) {
			return true;
		}
		return false;
	}

	/**
	 * 当前页是否有下一页
	 * 
	 * @return
	 */
	public boolean hasNext() {
		if (pages > 1 && currentPage < pages) {
			return true;
		}
		return false;
	}

	public long getTotal() {
		return total;
	}

	public void setTotal(long total) {
		this.total = total;
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public int getPages() {
		return pages;
	}

	public void setPages(int pages) {
		this.pages = pages;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public List<T> getList() {
		return list;
	}

	public void setList(List<T> list) {
		this.list = list;
	}
}
